﻿using System;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 不卡
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }

    private  void button1_Click(object sender, EventArgs e)
    {
      button1.Enabled = false;
      Do(10, $"0#来了");
      //Task task = new Task(() =>
      //{
      int i = 0;
      while (++i < 10)
      {
        Do(i * 500, $"{i}#来了");
      }
      notifyUi(() => { button1.Enabled = true; });
      //}
      //);
      //task.Start();


    }

    private void setStatus(string value)
    {
      toolStripStatusLabel1.Text = "我来了";
    }

    void Do(int ms, string value)
    {
      Thread.Sleep(ms);
      MethodInvoker mi = new MethodInvoker(() => { toolStripStatusLabel1.Text = value; });
      BeginInvoke(mi);
    }

    void notifyUi(Action action)
    {
      MethodInvoker mi = new MethodInvoker(action);
      BeginInvoke(mi);
    }


  }
}
